﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Ccit.Utils;
using Ccit.Global;
using Ccit.OA.Utils;

namespace Ccit.OA.NewsCenter
{
    public class QueryORA : IQuery
    {
        #region
        
        /// <summary>
        /// 查询本人的快速查询条件表的信息
        /// </summary>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public List<MsQueryClause> GetFastClauseList(string loginUser)
        {
            string cmdText = string.Empty;
            if (string.IsNullOrEmpty(loginUser)) return null;
            cmdText = "SELECT NEWS_A8_10 AS CLAUSEID,NEWS_A8_40 AS  CLAUSENAME FROM NEWS_A8 WHERE NEWS_A8_9994='" + loginUser + "'";
            List<MsQueryClause> msclist = new List<MsQueryClause>();
            using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText))
            {
                while (ireader.Read())
                {
                    MsQueryClause msc = new MsQueryClause();
                    msc.ClauseId = ireader["CLAUSEID"].ToString();
                    msc.ClauseName = ireader["CLAUSENAME"].ToString();
                    msclist.Add(msc);
                }
            }
            return msclist;
        }
        /// <summary>
        /// delete fast clause
        /// </summary>
        /// <param name="ClauseId"></param>
        /// <returns></returns>
        public List<string> RemoveFastClause(string ClauseId)
        {
            List<string> strlist = new List<string>();
            if (string.IsNullOrEmpty(ClauseId))
            {
                strlist.Add("-999");
                strlist.Add("删除失败,缺少必要的参数");
                return strlist;
            }
            string cmdText = " DELETE FROM NEWS_A8 WHERE NEWS_A8_10='" + ClauseId + "'";
            if (0 < DataAccessor.ExecuteNonQuery(cmdText))
            {
                strlist.Add("1");
                strlist.Add("删除成功");
            }
            else
            {
                strlist.Add("-1");
                strlist.Add("删除失败,系统忙,请稍候再试");
            }
            return strlist;
        }
        /// <summary>
        /// save fast clause
        /// </summary>
        /// <param name="msc"></param>
        /// <param name="addPlate"></param>
        /// <returns></returns>
        public List<string> SaveFastClause(MsQueryClause msc, string addPlate)
        {
            if (msc == null) return null;
            List<string> strlist = new List<string>();
            string[] pubMsg = SessionExt.GetSysFieldSQL("NEWS_A8");
            LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            string strMaxId = DataInterface.GetMaxId("NEWS_A8", "NEWS_A8_10").ToString();
            //快速查询条件表
            string strFastClause = "INSERT INTO NEWS_A8 (NEWS_A8_10,NEWS_A8_20,NEWS_A8_30,NEWS_A8_40,NEWS_A8_50,NEWS_A8_60,NEWS_A8_70," + pubMsg[0] + ") " +
                            " VALUES ('" + strMaxId + "','" + loginUser.UserId + "','" + msc.ClauseType + "','" + msc.ClauseName + "','" + msc.ClauseContent + "','" + msc.ClauseFlag + "','" + msc.WindowFlag + "'," + pubMsg[1] + ")";
            if (0 < DataAccessor.ExecuteNonQuery(strFastClause))
            {
                strlist.Add("1");
                strlist.Add("保存成功");
            }
            else
            {
                strlist.Add("-1");
                strlist.Add("保存失败,系统忙,请稍后再试");
            }
            if (addPlate == "1")
            {
                //版块表
                string strPlate = "INSERT INTO NEWS_B2 (NEWS_B2_10,NEWS_B2_20,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100,NEWS_B2_120)";
                strPlate += "VALUES ('" + strMaxId + "','" + msc.ClauseName + "','0','1','1','0')";
                if (0 < DataAccessor.ExecuteNonQuery(strPlate))
                {
                    strlist.Add("1");
                    strlist.Add("保存成功");
                }
                else
                {
                    strlist.Add("-1");
                    strlist.Add("保存失败,系统忙,请稍后再试");
                }
            }
            return strlist;
        }
        #endregion

        #region IQuery 成员


        public MsQueryClause GetClauseObj(string clauseId)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IQuery 成员


        public List<string> SaveFastClause(MsQueryClause msc, string addPlate, string Type)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IQuery 成员

        public List<MsQueryClause> GetFastClauseList(string loginUser, string PlateIds)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IQuery 成员


        public List<string> SaveFastClause(MsQueryClause msc, string addPlate, string Type, string pageSource)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
